package authoritah.ui.spend;

import javax.swing.ComboBoxModel;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

import authoritah.db.Event;
import authoritah.db.Item;
import authoritah.db.Member;
import authoritah.db.Spend;


public class SpendModel {
	private SpendTableModel tableModel;
	private ComboBoxModel memberModel;
	private ComboBoxModel eventModel;
	private ComboBoxModel itemModel;
	private Document pointsDocument;
	
	public SpendModel() {
		tableModel = new SpendTableModel(Spend.getAllSpends());
	}

	public SpendTableModel getTableModel() {
		return tableModel;
	}

	public void setMemberModel(ComboBoxModel memberModel) {
		this.memberModel = memberModel;
	}

	public void setEventModel(ComboBoxModel eventModel) {
		this.eventModel = eventModel;
	}

	public void setItemModel(ComboBoxModel itemModel) {
		this.itemModel = itemModel;
	}

	public void setPointsDocument(Document pointsDocument) {
		this.pointsDocument = pointsDocument;
	}

	public Event getEvent() {
		return (Event)eventModel.getSelectedItem();
	}
	
	public Item getItem() {
		return (Item)itemModel.getSelectedItem();
	}
	
	public Member getMember() {
		return (Member)memberModel.getSelectedItem();
	}
	
	public int getPointsSpent() {
		try {
			return Integer.parseInt(pointsDocument.getText(0, pointsDocument.getLength()));
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		return 0;
	}
}
